package com.czkevin.biliwsclient.gift;

import com.alibaba.fastjson.JSONObject;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;

public class GiftInfo {

    public final int id;
    public final String name;
    public final int price;
    public final int type;
    public final CoinType coinType;
    public final String desc;
    public final String rights;
    public final boolean withDescAndRights;

    public GiftInfo(int id, String name, int price, int type, CoinType coinType, String desc, String rights) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.type = type;
        this.coinType = coinType;
        this.desc = desc;
        this.rights = rights;
        withDescAndRights = true;
    }

    public GiftInfo(int id, String name, int price, int type, CoinType coinType) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.type = type;
        this.coinType = coinType;
        this.desc = "<unknown>";
        this.rights = "<unknown>";
        withDescAndRights = false;
    }

    public static GiftInfo decode(JSONObject gift) {
        return new GiftInfo(
            gift.getIntValue("id"),
            gift.getString("name"),
            gift.getIntValue("price"),
            gift.getIntValue("type"),
            CoinType.valueOf(gift.getString("coin_type").toUpperCase()),
            gift.getString("desc"),
            gift.getString("rights")
        );
    }

}
